#ifndef __SESSION_H__
#define __SESSION_H__
#include <string>
#include "ringBuffer.h"
#include <netinet/in.h>

using namespace std;

enum ConnStatus
{
	INACTIVATE = 1,
	ACTIVATE
};

class WriteData
{
public:
	WriteData() : len(0), data(nullptr){}
	~WriteData()
	{
		if (data != nullptr)
		{
			delete []data;
			data = nullptr;
		}
		return;
	}

	int len;
	unsigned char *data;
};

void modify_event(int epfd, int fd, uint32_t events, int op);
class BaseSession
{
public:
	BaseSession(); 
	virtual ~BaseSession();

	char thread_index = -1;
	ConnStatus status = INACTIVATE;

	void init_session(int _sock_fd, std::string ip);

	int sock_fd;
	string url;
	string filename;
	string peer_ip;
	int peer_port;
	struct sockaddr_in remote_addr; // 媒体数据接收端ip、port
	RingBuffer<shared_ptr<WriteData>> write_buffer;
	std::chrono::time_point<std::chrono::steady_clock> version;  
	/*发送数据*/
	int send_data(unsigned char *data, int len);

	// 接收信令
	int recv_data(unsigned char* buff, int len);
};
#endif
